/**
 * Created by jiaaobo on 16/11/29.
 */

import Util from "util";
import API  from "api";
import CONST from  "const";
import MyOrderItem from  "../view/MyOrderItem";
import BaseScroll from  "../../../common/component/pullScroll/BaseScroll.vue";

export default{
  name: "myOrder",
  data(){
    return {
      orderList : [],
      orderType : "",
      selectTab : "",
      tabList : [
        {
          ID : 0,
          DESC : "未开始"
        },
        {
          ID : 1,
          DESC : "已结束"
        }
      ],
      isEnd : false,
      loading : false,
      h : window.screen.availHeight - 39
    }
  },

  computed: {


  },

  mounted: function () {
    this.loadOrderList(false);
    this.selectTab = this.tabList[0];
    console.log(this.h);
  },

  methods: {

    refresh : function(){
      console.log("refresh..");
      this.isEnd = false;
      this.loadOrderList(false);

    },

    loadMore : function(){
      this.loading = true;
      console.log("load more..");
      this.loadOrderList(true);
    },

    onTabInput : function(a){
      this.isEnd = false;
      this.page = 1;
      this.loadOrderList(false);
    },

    loadOrderList : function(isLoadMore){
      let config =  isLoadMore ?  {} : {hasLoading : true};
      let requestTime = requestTime || 0;

      if(isLoadMore && this.orderList.length >0){
        //获得最后一条时间
        requestTime = this.orderList[this.orderList.length-1].endTime;
      }

        console.log(this.selectTab.ID);

      var obj = {
        type : this.selectTab.ID || 0,
        requestTime : requestTime
      };


      API.biz.queryAppointList(obj,config)
        .then((res)=>{
          //加载完成
          if(res.bizData.length <=0){
            this.isEnd = true;
          }
          else{
            this.isEnd = false;
          }

          if(isLoadMore){
            this.orderList =  this.orderList.concat(res.bizData);
          }
          else{
            this.orderList = res.bizData;
          }

          this.loading = false;
          this.$refs.pullScroll.scrollDown(!isLoadMore ? 'refresh' : 'loadMore');

        });
    }
  },

  components: {
    MyOrderItem,
    BaseScroll
  }
}
